package szc.common.code.counter;

import szc.common.code.rule.CodeLineParserAbstract;
import szc.common.code.rule.NormalCodeLineParser;

import java.util.LinkedList;
import java.util.List;

/**
 * @desc java有效代码行统计
 * @author songzc
 * @date 2022/6/18
 */
public class ValidCodeLineCounter {
    private List<CodeLineParserAbstract> validCodeLineParser = new LinkedList<CodeLineParserAbstract>();
    private int validCodeLineCounter = 0;
    private boolean isValidCodeLine = false;

    public ValidCodeLineCounter(){
        CodeLineParserAbstract parser = new NormalCodeLineParser();
        this.validCodeLineParser.add(parser);
    }

    public void countValidCodeLine(String codeLine){
        for(CodeLineParserAbstract parser : this.validCodeLineParser){
            parser.setCodeLine(codeLine);
            if (parser.parseCodeLine()){
                validCodeLineCounter++;
                this.isValidCodeLine = true;
            } else {
                this.isValidCodeLine = false;
            }
        }
    }

    public int getLineCount(){
        return this.validCodeLineCounter;
    }

    public boolean isValidCodeLine(){
        return this.isValidCodeLine;
    }
}
